import configparser


#生成configparser文件
# config = configparser.ConfigParser()
# config["DEFAULT"] = {'ServerAliveInterval': '45', 'Compression': 'yes', 'CompressionLevel': '9'}
#
# config['bitbucket.org'] = {}
# config['bitbucket.org']['User'] = 'hg'
# config['topsecret.server.com'] = {}
# topsecret = config['topsecret.server.com']
# topsecret['Host Port'] = '50022'  # mutates the parser
# topsecret['ForwardX11'] = 'no'  # same here
# config['DEFAULT']['ForwardX11'] = 'yes'
# with open('example.ini', 'w') as configfile:
#     config.write(configfile)


#读取
config = configparser.ConfigParser()
print(config.sections())
print(config.read('example.ini'))
print(config.sections())
print('bitbucket.org'in config)
print('baidu.com' in config)

print(config['bitbucket.org']['User'])
print(config['DEFAULT']['compressionlevel'])
#
for key  in config['DEFAULT'].items():
    print(key)


